package com.leftheart.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
@EnableWebMvc
public class MyMvcConfig implements WebMvcConfigurer {
    /**
     * 加载静态文件
     */

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/").addResourceLocations("/favicon.ico");;

        WebMvcConfigurer.super.addResourceHandlers(registry);
    }




//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        //注册TestInterceptor拦截器
//        InterceptorRegistration registration = registry.addInterceptor(new LoginHandlerInterceptor());
//        registration.addPathPatterns("/admin/**");                      //所有路径都被拦截
//        registration.excludePathPatterns(                         //添加不拦截路径
//                "/index.html",            //登录
//
////                "/**/*.html",            //html静态资源
//                "/static/**"             //js静态资源
////                "/**/*.css",             //css静态资源
////                "/**/*.woff",
////                "/**/*.ttf"
//        );
//    }
    /**
     * 配置主页面路径
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/main.html").setViewName("admin/index");
    }



}
